home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK2.toast / Development Kits (Disc 2) / QuickTime / Programming Stuff / Sample Code / Music Architecture / Mixed Bag / BigEasy / BigEasyGrafish.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-13  |  5.1 KB  |  317 lines  |  [TEXT/KAHL]

  1. /*
  2.     File:        BigEasyGrafish.c
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Written by:    xxx put writers here xxx
  7.  
  8.     Copyright:    © 1991, 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     This file is used in these builds: Warhol
  11.  
  12.     Change History (most recent first):
  13.  
  14.          <6+> universal headers
  15.          <6>      9-8-94    dvb        
  16.          <4>     1/20/92    dvb        Add more routines.
  17.          <3>     5/23/91    PH        changes for THINK 5
  18.          <2>     4/25/91    JB        Changing to new THINK_C interface files
  19.  
  20.     To Do:
  21. */
  22.  
  23. /* file: BigEasyGrafish.c
  24.  *
  25.  * Started 4 August 1989, more or less.
  26.  *
  27.  * A set of routines for doing certain
  28.  * QuickDraw like operations on the Macintosh.
  29.  *
  30.  */
  31.  
  32.  
  33.  
  34. /*--------------------------------
  35.     Inclusions
  36. --------------------------------*/
  37.  
  38. #include <QuickDraw.h>
  39. #include <Resources.h>
  40. #include <Memory.h>
  41. #include <Palettes.h>
  42. #include <Gestalt.h>
  43.  
  44. #define BigEasyGrafish
  45.  
  46. #include "BigEasyGrafish.h"
  47.  
  48.  
  49. /*--------------------------------
  50.     Data
  51. --------------------------------*/
  52.  
  53. unsigned char dGrayPat[] = {0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA};
  54. unsigned char dBlackPat[] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
  55.  
  56.  
  57. /*--------------------------------
  58.     Local Variables & Routines
  59. --------------------------------*/
  60.  
  61. static Boolean GestaltColor(void);
  62. static Boolean gBEGHasColor;
  63. static Boolean gDoneColorGestalt = false;
  64.  
  65.  
  66. /*--------------------------------
  67.     Routines
  68. --------------------------------*/
  69.  
  70. void RGBFore(unsigned short r,unsigned short g,unsigned short b)
  71.     {
  72.     GestaltColor();
  73.     if(gBEGHasColor || 1)
  74.         {
  75.         RGBColor c;
  76.  
  77.         c.red = r;
  78.         c.green = g;
  79.         c.blue = b;
  80.         RGBForeColor(&c);
  81.         }
  82.     else
  83.         {
  84.         unsigned long x;
  85.  
  86.         x = r + g + b;
  87.         if ( x > (3 * 32768))
  88.             ForeColor(whiteColor);
  89.         else
  90.             ForeColor(blackColor);
  91.         }
  92.     }
  93.  
  94. void RGBBack(unsigned short r,unsigned short g,unsigned short b)
  95.     {
  96.     GestaltColor();
  97.     if(gBEGHasColor || 1)
  98.         {
  99.         RGBColor c;
  100.  
  101.         c.red = r;
  102.         c.green = g;
  103.         c.blue = b;
  104.         RGBBackColor(&c);
  105.         }
  106.     else
  107.         {
  108.         unsigned long x;
  109.  
  110.         x = r + g + b;
  111.         if ( x > (3 * 32768))
  112.             BackColor(whiteColor);
  113.         else
  114.             BackColor(blackColor);
  115.         }
  116.     }
  117.  
  118. void GoWhite()
  119.     {
  120.     PenPat((Pattern *)dBlackPat);
  121.     ForeColor(whiteColor);
  122.     }
  123.  
  124. void GoGray()
  125.     {
  126.     PenPat((Pattern *)dBlackPat);
  127.     RGBFore(32768,32768,32768);
  128.     }
  129.  
  130. void GoBlack()
  131.     {
  132.     PenPat((Pattern *)dBlackPat);
  133.     ForeColor(blackColor);
  134.     }
  135.  
  136. void GoBW()
  137.     {
  138.     PenNormal();
  139.     ForeColor(blackColor);
  140.     BackColor(whiteColor);
  141.     }
  142.  
  143. void RGBOp(unsigned short r,unsigned short g,unsigned short b)
  144.     {
  145.     RGBColor c;
  146.     c.red = r;
  147.     c.green = g;
  148.     c.blue = b;
  149.     OpColor(&c);
  150.     }
  151.  
  152. void RGBHilite(unsigned short r,unsigned short g,unsigned short b)
  153.     {
  154.     RGBColor c;
  155.     c.red = r;
  156.     c.green = g;
  157.     c.blue = b;
  158.     HiliteColor(&c);
  159.     }
  160.  
  161. void PmHilite(short h)
  162.     {
  163.     PaletteHandle ph;
  164.     RGBColor c;
  165.  
  166.     ph = GetPalette(FrontWindow());
  167.     GetEntryColor(ph,h,&c);
  168.     HiliteColor(&c);
  169.     }
  170.  
  171.  
  172.  
  173. void RampColorTable(CTabHandle ctH,short start,short length,
  174.         unsigned short r1,unsigned short g1,unsigned short b1,
  175.         unsigned short r2,unsigned short g2,unsigned short b2)
  176. /*
  177.   * Make an rgb ramp in the color table handle passed.
  178.   */
  179.     {
  180.     long dr,dg,db;
  181.     short i;
  182.     ColorSpec *c;
  183.  
  184.     dr = r2-r1;
  185.     dg = g2-g1;
  186.     db = b2-b1;
  187.  
  188.     c = &(**ctH).ctTable[start];
  189.     for(i = 0; i< length; i++)
  190.         {
  191.         c->value = start+i;
  192.         c->rgb.red = r1+ dr*i/length;
  193.         c->rgb.green = g1+ dg*i/length;
  194.         c->rgb.blue = b1+ db*i/length;
  195.         c++;
  196.         }
  197.     }
  198.     
  199. void FrameRectOutside(Rect *r)
  200.     {
  201.     Rect r2;
  202.     PenState ps;
  203.  
  204.     r2 = *r;
  205.     GetPenState(&ps);
  206.     InsetRect(&r2,-ps.pnSize.h,-ps.pnSize.v);
  207.     FrameRect(&r2);
  208.     }
  209.  
  210. void DrawIcl8Resource(short id,Rect *r)
  211. /*
  212.  * Draw the icl8, disregarding masks and such
  213.  */
  214.     {
  215.     PixMap pm;
  216.     Handle h;
  217.  
  218.     h = GetResource('icl8',id);
  219.     if(!h)
  220.         {
  221.         PaintRect(r);
  222.         return;
  223.         }
  224.  
  225.     HLock(h);
  226.  
  227.     pm.baseAddr = *h;
  228.     pm.rowBytes = 32 | 0x8000;
  229.     pm.bounds.top = pm.bounds.left = 0;
  230.     pm.bounds.bottom = pm.bounds.right = 32;
  231.     pm.pmVersion = 0;
  232.     pm.packType = 0;
  233.     pm.packSize = 0;
  234.     pm.hRes = pm.vRes = 0x00480000;
  235.     pm.pixelType = 0;
  236.     pm.pixelSize = 8;
  237.     pm.cmpCount = 1;
  238.     pm.cmpSize = 8;
  239.     pm.planeBytes = 0;
  240.     pm.pmTable = GetCTable(8);
  241.     pm.pmReserved = 0;
  242.  
  243.     CopyBits((void *)&pm,&qd.thePort->portBits,&pm.bounds,r,0,0);
  244.  
  245.     DisposeCTable(pm.pmTable);
  246.     HUnlock(h);
  247.     ReleaseResource(h);
  248.     }
  249.  
  250.  
  251. Boolean EasyHasColor(void)
  252. /*
  253.  * In a nutshell: returns True of the
  254.  * 0,0-point of the current port is
  255.  * anything besides a b/w situation.
  256.  */
  257.     {
  258.     GDHandle gdH;
  259.     Rect r;
  260.     Boolean b;
  261.  
  262.     if(GestaltColor)
  263.         {
  264.         r = qd.thePort->portRect;
  265.         LocalToGlobal((Point *)&r.top);
  266.         LocalToGlobal((Point *)&r.bottom);
  267.         gdH = GetMaxDevice(&r);
  268.         if(gdH)
  269.             b = (**(**gdH).gdPMap).pixelSize > 1;
  270.         else
  271.             b = false;        /* not on any device... whatever */
  272.         }
  273.     else
  274.         b = false;
  275.  
  276.     return b;
  277.     }
  278.  
  279.  
  280. Boolean GestaltColor(void)
  281.     {
  282.     long result;
  283.  
  284.     if(!gDoneColorGestalt)
  285.         gBEGHasColor = (Gestalt('qdrw',&result)) ?
  286.                 false : (result & (1<<gestaltHasDeepGWorlds)) != 0;
  287.  
  288.     return gBEGHasColor;
  289.     }
  290.  
  291. void DrawPixMap(PixMap *pm,Rect *src,Rect *dst,short mode)
  292.     {
  293.     Rect srcR,dstR;
  294.  
  295.     if(src)
  296.         srcR = *src;
  297.     else
  298.         srcR = pm->bounds;
  299.  
  300.     if(dst)
  301.         dstR = *dst;
  302.     else
  303.         dstR = srcR;
  304.  
  305.     CopyBits((BitMap *)pm,&qd.thePort->portBits,&srcR,&dstR,mode,nil);
  306.     }
  307.  
  308. void DrawPixMapOffset(PixMap *pm,short x,short y,short mode)
  309.     {
  310.     Rect r;
  311.  
  312.     r = pm->bounds;
  313.     OffsetRect(&r,x,y);
  314.     DrawPixMap(pm,nil,&r,mode);
  315.     }
  316.  
  317.